package com.mystyle.le.liuxiang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mystyle.le.liuxiang.R;
import com.mystyle.le.liuxiang.beans.HeadList;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by le on 2016/10/26.
 */
public class EntertainmentAdapter extends BaseAdapter {
    private List<HeadList> lists;
    private Context context;
    private LayoutInflater inflater;

    public EntertainmentAdapter(List<HeadList> lists, Context context) {
        this.lists = lists;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return lists==null?0:lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = inflater.inflate(R.layout.head_list_layout,parent,false);
            holder = new ViewHolder();
            holder.head_list_iv = (ImageView) convertView.findViewById(R.id.head_list_iv);
            holder.head_list_ivs = (ImageView) convertView.findViewById(R.id.head_list_ivs);
            holder.head_list_tv = (TextView) convertView.findViewById(R.id.head_list_tv);
            holder.head_list_tvs = (TextView) convertView.findViewById(R.id.head_list_tvs);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        HeadList headList = lists.get(position);
        String user_avatar = headList.getUser_avatar();
        Picasso.with(context).load(user_avatar).into(holder.head_list_ivs);

        String img = headList.getImg();
        Picasso.with(context).load(img).into(holder.head_list_iv);

        holder.head_list_tv.setText(headList.getTitle());
        holder.head_list_tvs.setText(headList.getUser_name());

        return convertView;
    }

    class ViewHolder{
        TextView head_list_tv,head_list_tvs;
        ImageView head_list_iv,head_list_ivs;
    }
}
